package cn.wzy.controller;

import cn.wzy.service.UserService;
import cn.wzy.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

/**
 * @author nihaowzy
 * @date 2020/12/22 20:15
 */
@WebServlet("/page.do")
public class PageServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try{
            String tag = req.getParameter("service");
            Method method = this.getClass().getDeclaredMethod(tag, HttpServletRequest.class, HttpServletResponse.class);
            method.invoke(this,req,resp);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 跳转到main.jsp
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void main(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.getRequestDispatcher("WEB-INF/view/main.jsp").forward(req,resp);
    }

    /**
     * 跳转到user/list.jsp  用户列表页面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void userList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/user/list.jsp").forward(req,resp);
    }

    /**
     * 跳转到customer/list.jsp 客户列表页面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void customerList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/customer/list.jsp").forward(req,resp);
    }


    /**
     * 跳转到customer/list.jsp 客户列表页面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void updatePassword(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/updatePwd.jsp").forward(req,resp);
    }

    /**
     * 跳转到修改头像界面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void updateImg(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/updateImg.jsp").forward(req,resp);
    }



}
